<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@include file="/WEB-INF/jsp/common/taglibs.jsp" %>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <title>资源管理</title>
    <%@include file="/WEB-INF/jsp/common/meta2.jsp" %>
</head>
<body class="content-body">
<div class="container-fluid">

    <table class="table table-responsive table-bordered">
        <tr>
            <th colspan="20" class="bg-info text-center">表单编辑</th>
        </tr>
        <tr>
            <td>
                <form id="inputForm" action="${ctx}/common/resource/save" method="post"
                      class="form-horizontal col-sm-offset-2 col-sm-8" role="form">
                    <input name="id" value="${entity.id}" id="id" type="hidden"/>


                    <div class="form-group">
                        <label class="col-sm-4 control-label">资源名称：</label>

                        <div class="col-sm-4">
                            <input type="text" name="name" id="name"
                                   value="${entity.name}" placeholder="资源名称" class="form-control input-sm">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">URL：</label>

                        <div class="col-sm-4">
                            <input type="text" name="url" value="${entity.url}"
                                   id="url" placeholder="URL" class="form-control input-sm">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">提示语：</label>

                        <div class="col-sm-4">
                            <input type="text" name="title" value="${entity.title}"
                                   id="title" placeholder="提示语" class="form-control input-sm">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">资源组：</label>

                        <div class="col-sm-4">
                            <select id="groupId" name="groupId" class="input-sm form-control">
                                <c:forEach items="${types}" var="type">
                                    <optgroup label="${type.name}">
                                        <c:forEach items="${groups}" var="group">
                                            <c:if test="${type.code == group.enumType.code}">
                                                <option ${entity.groupId == group.id ? 'selected':''}
                                                        value="${group.id}">
                                                        ${group.name}
                                                </option>
                                            </c:if>
                                        </c:forEach>
                                    </optgroup>

                                </c:forEach>
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-4 control-label">组内序号：</label>


                        <div class="col-sm-3">
                            <input type="number" name="order" id="order" value="${entity.order}"
                                   placeholder="组内序号" class="form-control input-sm">
                        </div>
                        <div class="col-sm-5 form-control-static">
                            <span class="text-info">只能填写数字，数字越大菜单显示越在后</span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">图标：</label>

                        <div class="col-sm-3">
                            <input type="text" name="icon" id="icon" readonly="readonly" class="form-control input-sm"
                                   value="${entity.icon != null && fn:containsIgnoreCase(entity.icon, 'glyphicon') ?entity.icon: 'glyphicon-list-alt'}">
                        </div>
                        <div class="col-sm-4 form-control-static">
                            <span id="iconBar"
                                  class="glyphicon ${entity.icon != null && fn:containsIgnoreCase(entity.icon, 'glyphicon') ?entity.icon: 'glyphicon-list-alt'}"></span>
                            <span class="text-info">单击选中下列图标</span>
                            <a id="iconContrlBtn" href="#" class="text-danger" type="button">隐藏</a>
                        </div>
                    </div>
                    <div id="iconGroup" class="form-group">
                        <div class="col-sm-10 col-sm-offset-2  well well-sm">
                            <%@include file="/WEB-INF/jsp/common/icons.jsp" %>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">菜单项：</label>

                        <div class="col-sm-8">

                            <label class="radio-inline">
                                <input type="radio" name="isMenu" value="true"  ${entity.isMenu ? 'checked':''}> 是
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="isMenu" value="false"  ${entity.isMenu ? '':'checked'}> 否
                            </label>

                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">禁用：</label>

                        <div class="col-sm-8">

                            <label class="radio-inline">
                                <input type="radio" name="enable" value="true" ${entity.enable? 'checked':''}> 是
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="enable" value="false" ${entity.enable? '':'checked'}> 否
                            </label>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">备注：</label>

                        <div class="col-sm-8">
                            <textarea class="form-control" rows="8" name="memo">${entity.memo}</textarea>
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-sm-offset-4 col-sm-8">
                            <input type="submit" value="确定" class="btn btn-info btn-sm">
                            <input class="btn btn-warning btn-sm" onclick="history.go(-1);" type="button"
                                   value="返回"/>
                        </div>
                    </div>


                </form>

            </td>
        </tr>
    </table>
</div>
</body>
</html>

<script>
    $(function () {

        $(".bs-glyphicons-list li").click(function () {
            var span = $("span", this);
            $("#iconBar").attr("class", $(span[0]).attr("class"));
            $("#icon").val($(span[1]).html());
            location.href = "#icon";
        });
        $("#inputForm").validate({
            rules: {
                order: {
                    digits: true
                },
                url: {
                    required: true
                },
                code: {
                    required: true,
                    maxlength: 30,
                    digits: true,
                    remote: {
                        type: "POST",
                        url: "${ctx}/platform/subject/validateSave",
                        beforeSend: function (xhr) {
                            top.loadingModal.stop = true;
                        },
                        complete: function (xhr, status) {
                            top.loadingModal.stop = false;
                        },
                        data: {
                            id: $("#id").val(),
                            code: function () {
                                return $("#code").val().trim();
                            }
                        }
                    }
                },
                schoolId: {
                    required: true
                },
                collegeId: {
                    required: true
                },
                name: {
                    required: true,
                    maxlength: 30
                },
                memo: {
                    maxlength: 500
                }
            },
            messages: {
                code: {
                    remote: "专业编码重复！"
                }
            }
        });

        $("#iconContrlBtn").click(function () {
            if ($(this).text() == "隐藏") {
                $("#iconGroup").hide();
                $(this).text("显示");
            } else {
                $("#iconGroup").show();
                $(this).text("隐藏");
            }

        });
    });


</script>
